home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / mc.lha / MC / mc_fract.c < prev    next >
C/C++ Source or Header  |  1995-10-31  |  7KB  |  289 lines

  1. /******************************************************************************
  2. **                                         **
  3. ** MultiColor-Demo-Fract                             **
  4. **                                         **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 01.10.95                                 **
  7. ******************************************************************************/
  8.  
  9. // good spots
  10. //
  11. // -1.460652  -1.454792  -0.002050  +0.002050  300 1
  12. // -1.279381  -1.267661  -0.059969  -0.051769  300 1
  13. // +0.308857  +0.319540  -0.032816  -0.025317  300 1
  14. // +0.3121861 +0.3128537 -0.0313250 -0.0308563 400 0
  15.  
  16. #include "sc:source/mc/multicolor.h"
  17.  
  18. /* Protos */
  19.  
  20. void OpenAll(void);
  21. void CloseAll(void);
  22. void CRange(MCPoint *ctab,UWORD six,MCPoint sc,UWORD eix,MCPoint ec);
  23. void Palette(MCPoint *ctab);
  24. void Fract(double x1,double x2,double y1,double y2,UWORD it,UWORD cs,MCPoint *ctab);
  25. void Usage(void);
  26.  
  27. /* defines */
  28.  
  29. extern struct ExecBase        *SysBase;
  30. struct IntuitionBase        *IntuitionBase=0l;
  31. struct GfxBase                *GfxBase=0l;
  32. struct Screen                *scr=0l;
  33. struct Window                *win=0l;
  34. MCHandle                    *mch=0l;
  35.  
  36. #define maxc 256
  37. MCPoint                     ctab[maxc+1];
  38.  
  39.  
  40. struct TagItem scrtags[]={
  41.     SA_Left,        0,
  42.     SA_Top,         0,
  43.     SA_Width,        0,
  44.     SA_Height,        0,
  45.     SA_Depth,        0,
  46.     SA_Colors,        0l,
  47.     SA_Type,        CUSTOMSCREEN,
  48.     SA_DisplayID,    PAL_MONITOR_ID,
  49.     TAG_DONE
  50. };
  51.  
  52. struct TagItem wintags[]={
  53.     WA_Left,        0,
  54.     WA_Top,         0,
  55.     WA_Width,        0,
  56.     WA_Height,        0,
  57.     WA_IDCMP,        IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  58.     WA_Flags,        WFLG_SMART_REFRESH|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  59.     WA_CustomScreen,0l,
  60.     TAG_DONE
  61. };
  62.  
  63. /* Funktions */
  64.  
  65. void OpenAll(void)
  66. {
  67. //    if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
  68.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39))) CloseAll();
  69.     if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37))) CloseAll();
  70.  
  71.     if(!(scr=OpenScreenTagList(0l,scrtags))) CloseAll();
  72.     wintags[6].ti_Data=(ULONG)scr;
  73.  
  74.     if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
  75. }
  76.  
  77. void CloseAll(void)
  78. {
  79.     if(win)                 CloseWindow(win);
  80.     if(scr)                 CloseScreen(scr);
  81.     if(GfxBase)             CloseLibrary((struct Library *)GfxBase);
  82.     if(IntuitionBase)       CloseLibrary((struct Library *)IntuitionBase);
  83.     exit(0);
  84. }
  85.  
  86. void CRange(MCPoint *ctab,UWORD six,MCPoint sc,UWORD eix,MCPoint ec)
  87. {
  88.     register UWORD i;
  89.     UWORD anz=eix-six;
  90.  
  91.     for(i=0;i<anz;i++)
  92.     {
  93.         sc.r+=(ec.r-sc.r)*i/anz;
  94.         sc.g+=(ec.g-sc.g)*i/anz;
  95.         sc.b+=(ec.b-sc.b)*i/anz;
  96.         ctab[six+i]=sc;
  97.     }
  98. }
  99.  
  100. void Palette(MCPoint *ctab)
  101. {
  102.     MCPoint p1,p2;
  103.  
  104.     p1.r=000;p1.g=000;p1.b=000;
  105.     p2.r=255;p2.g=000;p2.b=000;CRange(ctab,  0,p1, 32,p2);
  106.     p1.r=255;p1.g=255;p1.b=000;CRange(ctab, 32,p2, 64,p1);
  107.     p2.r=000;p2.g=255;p2.b=000;CRange(ctab, 64,p1, 96,p2);
  108.     p1.r=000;p1.g=255;p1.b=255;CRange(ctab, 96,p2,128,p1);
  109.     p2.r=000;p2.g=000;p2.b=255;CRange(ctab,128,p1,160,p2);
  110.     p1.r=255;p1.g=000;p1.b=255;CRange(ctab,160,p2,192,p1);
  111.     p2.r=255;p2.g=000;p2.b=000;CRange(ctab,192,p1,224,p2);
  112.     p1.r=000;p1.g=000;p1.b=000;CRange(ctab,224,p2,256,p1);
  113. }
  114.  
  115. void Fract(double x1,double x2,double y1,double y2,UWORD it,UWORD cs,MCPoint *ctab)
  116. {
  117.     struct IntuiMessage *imsg;
  118.     ULONG iclass;
  119.     USHORT icode;
  120.     register UBYTE quit=0;
  121.     register UWORD i,j,n,h;
  122.     double x,y,xd,yd,a,b,c,d;
  123.  
  124.     xd=(x2-x1)/mch->xres;
  125.     yd=(y2-y1)/mch->yres;
  126.     y=y1;
  127.     for(j=0;j<mch->yres;j++)
  128.     {
  129.         x=x1;
  130.         for(i=0;i<mch->xres;i++)
  131.         {
  132.             c=(a=x)*a;d=(b=y)*b;h=0;
  133.             for(n=1;n<it;n++)
  134.             {
  135.                 b=2.0*a*b+y;
  136.                 c=(a=c-d+x)*a;
  137.                 d=b*b;
  138.                 if(c+d>4.0)
  139.                 {
  140.                     h=n;
  141.                     break;
  142.                 }
  143.             }
  144.             MC_PutPixel(mch,i,j,&ctab[(h<<cs)%maxc]);
  145.             x+=xd;
  146.         }
  147.         y+=yd;
  148.         if(imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  149.         {
  150.             ReplyMsg((struct Message *)imsg);
  151.             quit=1;
  152.             break;
  153.         }
  154.     }
  155.  
  156.     while(!quit)
  157.     {
  158.         WaitPort(win->UserPort);
  159.         while(imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  160.         {
  161.             iclass    =imsg->Class;
  162.             icode    =imsg->Code;
  163.             ReplyMsg((struct Message *)imsg);
  164.             switch(iclass)
  165.             {
  166.                 case IDCMP_RAWKEY:
  167.                     switch(icode)
  168.                     {
  169.                         case 0x45:        /* ESC */
  170.                         case 0x40:        /* Space */
  171.                             quit=1;break;
  172.                     }
  173.                     break;
  174.             }
  175.         }
  176.     }
  177. }
  178.  
  179. void Usage(void)
  180. {
  181.     printf("Usage \n");
  182.     printf("\tmc_bleed typ res\n");
  183.     printf("\tres\\typ | 0=ECS | 1=AGA,GFX-Card\n");
  184.     printf("\t--------+-------+---------------\n");
  185.     printf("\t e (ehb)| 64    | -             \n");
  186.     printf("\t l (low)| 32    | 256           \n");
  187.     printf("\t h (hi )| 16    | 256           \n");
  188.     printf("\t s (shi)| --    | 256           \n");
  189.     printf("\t--------+-------+---------------\n");
  190. }
  191.  
  192. void main(int argc,char *argv[])
  193. {
  194.     UBYTE dep,typ,fail=0;
  195.     char res;
  196.     double x1=-2.0,x2=1.0,y1=-1.35,y2=1.35;
  197.     UWORD it=80,cs=2;
  198.  
  199.     if(argc>=3)
  200.     {
  201.         typ=atoi(argv[1])&1;
  202.         res=argv[2][0];
  203.         if(argc>=4) x1=atof(argv[3]);
  204.         if(argc>=5) x2=atof(argv[4]);
  205.         if(argc>=6) y1=atof(argv[5]);
  206.         if(argc>=7) y2=atof(argv[6]);
  207.         if(argc>=8) it=atoi(argv[7]);
  208.         if(argc>=9) cs=atoi(argv[8]);
  209.  
  210.         switch(typ)
  211.         {
  212.             case 0:     /* ECS */
  213.                 switch(res)
  214.                 {
  215.                     case 'E':
  216.                     case 'e':
  217.                         scrtags[4].ti_Data=dep=6;
  218.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  219.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  220.                         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  221.                         break;
  222.                     case 'L':
  223.                     case 'l':
  224.                         scrtags[4].ti_Data=dep=5;
  225.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  226.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  227.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  228.                         break;
  229.                     case 'H':
  230.                     case 'h':
  231.                         scrtags[4].ti_Data=dep=4;
  232.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  233.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  234.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  235.                         break;
  236.                     case 'S':
  237.                     case 's':
  238.                         fail=1;
  239.                         break;
  240.                 }
  241.                 break;
  242.             case 1:     /* AGA,GFX-Card */
  243.                 switch(res)
  244.                 {
  245.                     case 'E':
  246.                     case 'e':
  247.                         fail=1;
  248.                         break;
  249.                     case 'L':
  250.                     case 'l':
  251.                         scrtags[4].ti_Data=dep=8;
  252.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  253.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  254.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  255.                         break;
  256.                     case 'H':
  257.                     case 'h':
  258.                         scrtags[4].ti_Data=dep=8;
  259.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  260.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  261.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  262.                         break;
  263.                     case 'S':
  264.                     case 's':
  265.                         scrtags[4].ti_Data=dep=8;
  266.                         wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  267.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  268.                         scrtags[7].ti_Data|=SUPERLACE_KEY;
  269.                         break;
  270.                 }
  271.                 break;
  272.         }
  273.  
  274.         if(!fail)
  275.         {
  276.             OpenAll();
  277.             if(mch=MC_Init(scr,win,dep))
  278.             {
  279.                 Palette(ctab);
  280.                 Fract(x1,x2,y1,y2,it,cs,ctab);
  281.                 MC_Free(mch);
  282.             }
  283.         }
  284.         else Usage();
  285.     }
  286.     else Usage();
  287.     CloseAll();
  288. }
  289.